package com.zmn.uac.common.enums;

import com.zmn.uac.common.constant.ShopConstant;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * 类描述：店铺枚举
 *
 * @author xujie
 * @since 2021/05/18 18:34
 */
public enum ShopTypeEnum {

    /**
     * 服务商店铺
     */
    SP_TYPE(1, ShopConstant.SHOP_FROM_SERVICE_PROVIDE, "服务商店铺"),
    /**
     * 渠道店铺
     */
    CHANNEL_TYPE(2, ShopConstant.SHOP_FROM_CHANNEL, "渠道店铺");

    /**
     * 键
     */
    private final Integer key;

    private final String from;
    /**
     * 值
     */
    private final String value;

    ShopTypeEnum(Integer key, String from, String value) {

        this.key = key;
        this.from = from;
        this.value = value;
    }

    public Integer getKey() {
        return key;
    }


    public String getFrom() {
        return from;
    }

    public String getValue() {
        return value;
    }

    public static ShopTypeEnum getByFrom(String from) {

        return Stream.of(ShopTypeEnum.values())
                .filter(it -> Objects.equals(from, it.getFrom()))
                .findAny().orElse(null);
    }


    /**
     * 枚举校验
     *
     * @param key 键
     * @return boolean
     */
    public static boolean validate(Integer key) {

        for (ShopTypeEnum e : ShopTypeEnum.values()) {
            if (Objects.equals(e.getKey(), key)) {
                return true;
            }
        }
        return false;
    }

}
